package com.collectplus.express.parcel;

import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.collectplus.express.BaseActivity2;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppHttp;
import com.collectplus.express.logic.AppResult;
import com.collectplus.express.logic.DialogMgr;
import com.collectplus.express.logic.JSON;
import com.collectplus.express.logic.MsgID;
import com.collectplus.express.model.CollectingPassportBean;

import droid.frame.view.xlist.SListView;

/**
 * Created by lidandan on 2018/3/8.
 * 代收------已取走的包裹
 */
public class ParcelWaitTakenActivity extends BaseActivity2 {

    private SListView listView;
    private CollectingPassportBean item;
    private TextView parcelNumTv;
    private LinearLayout parcelNumLl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        item = (CollectingPassportBean) getIntent().getSerializableExtra("item");
        if (item != null) {
            AppHttp.getInstance().getCollectingParcelList(item.getStationId(), item.getStatus(), item.getId());
        } else {
            showToast("数据有误");
        }

        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.parcel_wait_taken_activity);
        super.findViewById();
        getAppTitle().setCommonTitle("取走的包裹");
        listView = (SListView) findViewById(R.id.listView);
        parcelNumTv = (TextView) findViewById(R.id.parcel_num_tv);
        parcelNumLl = (LinearLayout) findViewById(R.id.parcel_num_ll);

    }

    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case MsgID.get_collecting_parcel_list:
                cancelLoadingDialog();
                final AppResult<CollectingPassportBean> parcelResult = JSON.parseList(msg.obj, CollectingPassportBean.class);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (parcelResult.isSuccess()) {
                            ParcelWaitTakeAdapter adapter = new ParcelWaitTakeAdapter(parcelResult.getResultList(), getContext());
                            listView.setAdapter(adapter);
                            if (adapter.getItemsSize() == 0) {
                                parcelNumLl.setVisibility(View.GONE);
                            } else {
                                parcelNumTv.setText("以下共" + adapter.getItemsSize() + "个包裹于" + item.getTakeTime() + "取走");
                            }

                        } else {
                            showToast("获取数据失败");
                        }
                    }
                });
                return true;
            default:
                return super.handleMessage(msg);
        }

    }

}


